package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.ConfirmBeen;
import cn.xfdzx.android.apps.shop.bean.DetailPringBean;
import cn.xfdzx.android.apps.shop.bean.GoodsLimitBean;
import cn.xfdzx.android.apps.shop.contract.GoodsLimitContract;
import cn.xfdzx.android.apps.shop.contract.OrderDetailPringContract;
import cn.xfdzx.android.apps.shop.model.GoodsLimitModel;
import cn.xfdzx.android.apps.shop.model.OrderDetailPringModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author zf
 * @date 2020/8/17.
 * Description：商家订单详情
 */
public class OrderDetailPringPresenter extends BasePresenter<OrderDetailPringContract.View> implements OrderDetailPringContract.Presenter {

    private OrderDetailPringContract.Model model;

    public OrderDetailPringPresenter() {
        model = new OrderDetailPringModel();
    }

    @Override
    public void getOrderDetailPring(String order_id) {
        if (!isViewAttached()) {
            return;
        }

        model.getOrderDetailPring(order_id)
                .compose(RxScheduler.<DetailPringBean>Flo_io_main())
                .as(mView.<DetailPringBean>bindAutoDispose())
                .subscribe(new Consumer<DetailPringBean>() {
                    @Override
                    public void accept(DetailPringBean bean) throws Exception {
                        mView.getOrderDetailPringSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();

                    }
                });

    }

    @Override
    public void getCancleOrder(String order_id) {
        if (!isViewAttached()) {
            return;
        }

        model.getCancleOrder(order_id)
                .compose(RxScheduler.<DetailPringBean>Flo_io_main())
                .as(mView.<DetailPringBean>bindAutoDispose())
                .subscribe(new Consumer<DetailPringBean>() {
                    @Override
                    public void accept(DetailPringBean bean) throws Exception {
                        mView.getCancleOrderSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();

                    }
                });
    }

    @Override
    public void confirm(String order_id, int position) {
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.confirm(order_id)
                .compose(RxScheduler.<ConfirmBeen>Flo_io_main())
                .as(mView.<ConfirmBeen>bindAutoDispose())
                .subscribe(new Consumer<ConfirmBeen>() {
                    @Override
                    public void accept(ConfirmBeen bean) throws Exception {
                        mView.onConfirmSuccess(bean, position);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

}
